﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="userreg.aspx.cs" Inherits="userreg" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <script language="javascript" type="text/javascript">
        function ValidatePassword(source, arguments) {
            var data = arguments.Value.split('');
            //start by setting false
            arguments.IsValid = false;
            //check length
            if (data.length < 6 || data.length > 14) return;
            //check for uppercase, lowercase, and number
            var uc = false; var lc = false; var num = false;
            for (var c in data) {
                if (data[c] >= 'A' && data[c] <= 'Z') {
                    uc = true;
                } else if (data[c] >= 'a' && data[c] <= 'z') {
                    lc = true;
                } else if (data[c] >= '0' && data[c] <= '9') {
                    num = true;
                }
                if (uc && lc && num) {
                    arguments.IsValid = true;
                    break;
                }
            }
        } </script>
    <form id="form1" runat="server">
    <div>
        User Registration<br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
        <br />
        User name:<asp:TextBox ID="UserNameTextBox" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UserNameTextBox"
            ToolTip="Please use only letters and numbers with no spaces." ValidationExpression="\w{6,14}">*</asp:RegularExpressionValidator>
        <asp:RequiredFieldValidator ID="UserNameRequiredFieldValidator" runat="server" ControlToValidate="UserNameTextBox"
            ErrorMessage="Your username is required" ToolTip="Your username is required"></asp:RequiredFieldValidator>
        <br />
        Email:<asp:TextBox ID="EmailTextBox" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="EmailTextBox"
            ErrorMessage="Your email is not valid" ToolTip="Your email is not valid" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
        <asp:RequiredFieldValidator ID="EmailRequiredFieldValidator" runat="server" ControlToValidate="EmailTextBox"
            ErrorMessage="Your email is required" ToolTip="Your email is required"></asp:RequiredFieldValidator>
        <br />
        Password:<asp:TextBox ID="PasswordTextBox" runat="server" TextMode="Password"></asp:TextBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ValidatePassword"
            ControlToValidate="PasswordTextBox" ErrorMessage="Please enter 6-14 characters, including at least 1 uppercase letter, 1 lowercase letter, and 1 number."
            
            ToolTip="Please enter 6-14 characters, including at least 1 uppercase letter, 1 lowercase letter, and 1 number." 
            onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
        <asp:RequiredFieldValidator ID="PasswordRequiredFieldValidator" runat="server" ControlToValidate="PasswordTextBox"
            ErrorMessage="A password is required" ToolTip="A password is required"></asp:RequiredFieldValidator>
        <br />
        Confirm password:<asp:TextBox ID="ConfirmPasswordTextBox" runat="server" TextMode="Password"></asp:TextBox>
        <asp:CompareValidator ID="CompareValidator1" runat="server" 
            ControlToCompare="PasswordTextBox" ControlToValidate="ConfirmPasswordTextBox" 
            ErrorMessage="Both password fields must match" 
            ToolTip="Both password fields must match">*</asp:CompareValidator>
        <asp:RequiredFieldValidator ID="ConfirmPasswordRequiredFieldValidator" runat="server"
            ControlToValidate="ConfirmPasswordTextBox" ErrorMessage="You must confirm your password"
            ToolTip="You must confirm your password"></asp:RequiredFieldValidator>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Register" />
    </div>
    </form>
</body>
</html>
